﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Data.OleDb;
using System.IO;

namespace DiaryPlanner
{
    public partial class AlbumAddPhoto : Form
    {
        Album thisAlbumObject;
        String fileDir="";//file directory
        

        public AlbumAddPhoto(Album ab)
        {
            
            thisAlbumObject = ab;
            InitializeComponent();
            newDate.Text = System.DateTime.Now.ToString(); //현재 시간            
            
        }

        private void button1_Click(object sender, EventArgs e) //사진 추가 버튼
        {
            openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png;)|*.jpg; *.jpeg; *.gif; *.bmp; *.png;";
            DialogResult d = openFileDialog1.ShowDialog();            

            if (d != DialogResult.Cancel)
            {
                fileDir = openFileDialog1.FileName;
                photoMemo.Text = Path.GetFileName(fileDir);

                newPhoto.Image = Image.FromFile(fileDir);
             
            }            
        }

        private void button2_Click(object sender, EventArgs e)//취소 버튼
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)//추가 버튼
        {

            

            //사진을 등록하지 않음
            if(fileDir==""){
                return;            
            }


            AlbumPhoto ap = new AlbumPhoto(thisAlbumObject);
            //사진 저장            
            //파일명
            String fname = "AP" +"_"+ System.DateTime.Now.Year.ToString() + "_" +
                System.DateTime.Now.Month.ToString()+"_"+
                System.DateTime.Now.Day.ToString() + "_" +
                    System.DateTime.Now.Hour.ToString() + "_" +
                    System.DateTime.Now.Minute.ToString() + "_" +
                    System.DateTime.Now.Second.ToString() +"_" +
                Path.GetFileName(fileDir);

            File.Copy(fileDir, "./Album/" + thisAlbumObject.nowFolder.realName + "/" + fname);            
            ap.photoName = fname;
            //이미지
            ap.Size = new Size(100, 100);
            ap.Image = Image.FromFile("./Album/"+thisAlbumObject.nowFolder.realName+"/"+fname);
            ap.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;            
            
            ap.photoMemo = photoMemo.Text;//메모
            thisAlbumObject.nowFolder.PhotoList.Add(ap);//현재 폴더의 photoList에 사진 추가
            
            thisAlbumObject.viewAllPhoto();

            //사진 등록
            this.Close();
        }
    }
}
